#include <stdio.h>
#include <sys/select.h>
#include <termios.h>
#include <sys/ioctl.h>
 int _kbhit()
 {
        static const int STDIN = 0;
        static bool initialized = false; if (! initialized)
        {
            // Use termios to turn off line buffering
            termios term;
            tcgetattr(STDIN, &term);
            term.c_lflag &= ~ICANON;
            tcsetattr(STDIN, TCSANOW, &term);
            setbuf(stdin, NULL);
            initialized = true;
        } int bytesWaiting;
        ioctl(STDIN, FIONREAD, &bytesWaiting);
        return bytesWaiting;
        
}

/*
int main() {
	int t;
	for (int i = 0; i < 10; ++ i ) {
		if ( _kbhit() ) {
			printf("HEllo\n");
		}
	printf("%d\n", 0);
	getchar();
	}
}
*/
